package com.llz.leaveApply.demo;

import java.util.ArrayList;
import java.util.List;

public class Demo {
    public static void main(String[] args) {
        List<Person> people = new ArrayList<>();

        people.add(new Person("张三", 18, 90));
        people.add(new Person("李四", 20, 80));
        people.add(new Person("jack", 19, 85));
        people.add(new Person("tony", 17, 93));

        /*for (int j = 0; j < people.size(); j++) {
            for (int i = 0; i < people.size() - 1; i++) {
                if (compare(people.get(i).getAge(),people.get(i+1).getAge())) {
                    Person temp;
                    temp = people.get(i);
                    people.set(i, people.get(i + 1));
                    people.set(i + 1, temp);
                }

            }
        }
         System.out.println(people);*/
        // lambda表达式  就是函数式编程，就是把一个方法当作另一个方法的参数来使用
        mySort(people, (p1, p2) -> p1.getScore() > p2.getScore());

        System.out.println(people);
    }

    public static void mySort(List<Person> list, MyComparator mc) {
        for (int j = 0; j < list.size(); j++) {
            for (int i = 0; i < list.size() - 1; i++) {
                if (mc.test(list.get(i), list.get(i + 1))) {
                    Person temp;
                    temp = list.get(i);
                    list.set(i, list.get(i + 1));
                    list.set(i + 1, temp);
                }

            }
        }

    }
}

interface MyComparator {
    public abstract boolean test(Person p1, Person p2);
}
